home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_12 / 9n12042a < prev    next >
Text File  |  1991-10-13  |  2KB  |  42 lines

  1. #include "solid.h"
  2.  
  3. void draw_polygon(struct solid_obj *obj_ptr,
  4.     struct facet *facet_ptr)
  5. /*  draws a polygon representing a facet */
  6. {
  7.     struct vertex *vertex_ptr;
  8.     int x_first, y_first; /* screen coordinates for
  9.         first vertex of facet */
  10.     int vertex_ref_index;
  11.     float screen_x, screen_y; /* display screen
  12.         coordinates */
  13.     float x_normal, y_normal, z_normal; /* surface
  14.         normal vector */
  15.  
  16.     for (vertex_ref_index = 0; vertex_ref_index <
  17.         facet_ptr->vertex_count; ++vertex_ref_index) {
  18.         /* loop for each vertex of this facet */
  19.         vertex_ptr = obj_ptr->vertex_first +
  20.             facet_ptr->vertex_index[vertex_ref_index];
  21.         screen_x = proj_d * vertex_ptr->coord[0] /
  22.             proj_z;
  23.         screen_y = proj_d * vertex_ptr->coord[1] /
  24.             proj_z;
  25.         if (vertex_ref_index == 0) /* first vertex */
  26.             moveto(x_first = (int)(((screen_x -
  27.                 screen_x_min) / (screen_x_max -
  28.                 screen_x_min)) * maxx), y_first = (int)
  29.                 (((screen_y - screen_y_min) /
  30.                 (screen_y_max - screen_y_min)) *
  31.                 maxy));
  32.         else /* subsequent vertex */
  33.             lineto((int)(((screen_x - screen_x_min) /
  34.                 (screen_x_max - screen_x_min)) * maxx),
  35.                 (int)(((screen_y - screen_y_min) /
  36.                 (screen_y_max - screen_y_min)) *
  37.                 maxy));
  38.     }
  39.     lineto(x_first, y_first); /* back to 1st vertex */
  40.     return;
  41. }
  42.